#include <iostream>
#include <cstring>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>

#include "Comman.hpp"

int main()
{
    key_t key = GetKey();
    std::cout << "获取关键字成功, key: "<< key << std::endl;
    sleep(3);

    // 形成共享内存
    int shmid = getshm(key);
    std::cout << "形成共享内存成功, shmid: "<< shmid << std::endl;
    sleep(3);

    char* address = (char*)shmat(shmid, nullptr, 0);
    std::cout << "挂接地址空间成功" << std::endl;
    sleep(3);

    while (true)
    {
        std::cout << "Please enter: " << std::endl;
        scanf("%s", address);
        if (strcmp(address, "quit") == 0)
        {
            break;
        }
    }

    shmdt(address);
    std::cout << "去关联成功" << std::endl;
    sleep(3);

    return 0;
}